<?php
    class admin_provider_controller extends controllerBase
    {
        public function process()
        {
            $oDatabase = new database();
            
            if(isset($_POST['tb_provider_name']) && isset($_POST['tb_title_sector']) && isset($_POST['tb_price_sector']) && isset($_POST['tb_description_sector']) && isset($_POST['tb_image_sector']) && isset($_POST['tb_item_link_sector']))
            {
                if($_POST['tb_provider_name'] != '' && $_POST['tb_title_sector'] != '' && $_POST['tb_price_sector'] != '' && $_POST['tb_description_sector'] != '' && $_POST['tb_image_sector'] != '' && $_POST['tb_item_link_sector'] != '')
                {
                    $aData = array(
                        'provider_name' => $_POST['tb_provider_name'],
                        'provider_url' => $_POST['tb_provider_url'],
                        'host' => $_POST['tb_provider_host'],
                        'category_name' => $_POST['category_uri_title'],
                        'category_uri' => $_POST['category_uri'],
                        'categories_uri' => $_POST['list_categories'],
                        'title_sector' => $_POST['tb_title_sector'],
                        'price_sector' => $_POST['tb_price_sector'],
                        'description_sector' => $_POST['tb_description_sector'],
                        'image_sector' => $_POST['tb_image_sector'],
                        'item_link_sector' => $_POST['tb_item_link_sector'],
                    );
                    $result = $oDatabase->add('provider',$aData);
                    if(!$result)
                    {
                        $this->aParams['error'] = "Add provider fail!";
                    }
                    else
                    {
                        $this->aParams['message'] = "Add provider susscessful!";
                    }
                }
                else
                {
                    $this->aParams['error'] = "Some field miss!";
                }
            }
            
            $sQuery = "SELECT * FROM provider";
            $this->aParams['aProviders'] = $oDatabase->getListObject($sQuery,true,true);
        }
    }
?>
